using System;
using System.Linq;
using System.Collections.Generic;

namespace QuickBencher
{
    internal static class MeasurementExtensions
    {
        internal static void Print(this List<Measurement> measurements)
        {
            var printer = Printers.Get();

            Measurement.Header options = string.IsNullOrEmpty(measurements.First().Label)
                ? Measurement.Header.NotUsingLabels
                : Measurement.Header.UsingLabels;

            printer.Print(Measurement.GetHeader(options));
            measurements.ForEach(printer.Print);
        }

        internal static void PrintRehersal(this List<Measurement> measurements)
        {
            var printer = Printers.Get();
            printer.Print("Rehearsal ---");
            measurements.ForEach(printer.Print);

            var sum = measurements.Sum(m => m.TotalTime);

            printer.Print(string.Format("--- total:{0}sec", Measurement.FormatTime(sum)));
            printer.Print("");
        }
    }
}
